import sys
from confs import is_word

def output(word, ok):
    if word and is_word(word) and ok:
        print '%s\tx' % word

def main():
    '''
    output: words_filtered.txt
    (word, {freq; ':'super-freq..}) -> (word, 'x')
        if freq > super-freq for any super-freq and freq > 1
    '''
    prev_word = ''
    freq = 0
    max_super_freq = 1 # filtering words with frequency 1
    for line in sys.stdin:
        line = line.strip()
        word, val = line.split()
        if word != prev_word:
            output(prev_word, freq > max_super_freq)
            prev_word = word
            freq = 0
            max_super_freq = 1
            
        if val[0] == ':':
            val = val[1: ]
            super_freq = int(val)
            max_super_freq = max(max_super_freq, super_freq)
        else:
            freq = int(val)
    output(prev_word, freq > max_super_freq)

if __name__ == '__main__':
    main()
